package lib

func init() {
	Probs = append(Probs, Problem{
		Num:         386,
		Discription: "1...n数字字典序排序",
		Level:       2,
		Labels: map[string]int{
			"数学": 1,
		},
	})
}

//思路：
//优先*10
//*到>10了开始除10，末尾为9也除10，除完+1
func LexicalOrder(n int) []int {
	res := make([]int, n)
	res[0] = 1
	num := 1
	//必须这么写，要不然会无限循环
	for i := 1; i < n; i++ {
		if num*10 <= n {
			num *= 10
		} else {
			for num%10 == 9 || num == n {
				num /= 10
			}
			num++
		}
		res[i] = num
	}

	return res
}
